import Vue from 'vue';
import Vuex from 'vuex';
// import { stat } from 'fs/promises';

Vue.use(Vuex);

const state = {
    user: {
        // uid: '7dcdzzW6xa6ubzJaCobF2b54jEhER97iondTAY74Iw',
        uid: null,
        identity: null, // 用户身份，0普通用户， 1分销商
        avatar:null,//用户头像
        nickname:null,
        sex:null,
        birthday:null,
        mobile:null,//手机号
        issetpass:null//是否设置密码：0未设置，1已设置
    },
    dataLoading: true,
}

const mutations = {
    updateUser(state, obj) {
        state.user.uid = obj.uid;
        state.user.user_id = obj.user_id;
        // state.user.identity = 1; 
        state.user.identity = obj.identity; 
        state.user.avatar = obj.avatar;
        state.user.nickname = obj.nickname;   
        state.user.sex = obj.sex;
        state.user.birthday = obj.birthday;
        state.user.mobile = obj.mobile;
        state.user.issetpass = obj.issetpass;
    },
    changeLoadFinish(state, bool) {
        state.dataLoading = bool
    }
}

const  actions = {
    updateUser(context, obj) {
        context.commit('updateUser', obj)
    },
    changeLoadFinish(context, bool) {
        if (!!bool) {
            context.commit('changeLoadFinish', true);
        }
        if (!bool) {
            context.commit('changeLoadFinish', false);
        }
    }
}

export default new Vuex.Store({
    state,
    mutations,
    actions
})